package cn.est.controller;
import cn.est.pojo.PayOrder;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.PayOrderService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/payOrder")
public class PayOrderController {

    @Resource
    private PayOrderService payOrderService;

    @RequestMapping("/search")
    @ResponseBody
    public Page<PayOrder> searchPayOrder(@RequestParam Map<String,Object> param) {
        Page<PayOrder> payOrderPage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            payOrderPage  = payOrderService.queryPayOrderPageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payOrderPage;
    }

    @RequestMapping("/saveOrUpdatePayOrder")
    @ResponseBody
    public Result saveOrUpdatePayOrder(PayOrder payOrder){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(payOrder.getId())){
                flag=payOrderService.qdtxAddPayOrder(payOrder);
            }else{
                flag=payOrderService.qdtxModifyPayOrder(payOrder);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getPayOrderById")
    @ResponseBody
    public Result getPayOrderById(Long id){
        Result result= ResultUtils.returnSuccess();
        PayOrder payOrder=null;
        try {
            payOrder=payOrderService.getPayOrderById(id);
            result.setData(payOrder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemovePayOrder")
    @ResponseBody
    public Result batchRemovePayOrder(String ids){
        Integer flag=0;
        try {
            flag=payOrderService.qdtxBatchDeletePayOrder(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removePayOrderById")
    @ResponseBody
    public Result removePayOrderById(Long id){
        Integer flag=0;
        try {
            flag=payOrderService.qdtxDeletePayOrderById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
